var contextPath = function() {
    return  "/" + location.pathname.split("/")[1];
}

function getValue(name){
    var str=window.location.search;
    if (str.indexOf(name)!=-1){
        var pos_start=str.indexOf(name)+name.length+1;
        var pos_end=str.indexOf("&",pos_start);
        if (pos_end==-1){
            return str.substring(pos_start);
        } else {
            return str.substring(pos_start,pos_end);
        }
    } else {
        return "";
    }
}

var  themeName = getValue("theme");
if (themeName!=""){
    var cssurl  = $('#easyuiTheme').attr('href');
    var href = cssurl.substring(0, cssurl.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
    $('#easyuiTheme').attr('href', href);
}

//将表单数据转为json
function form2Json(id) {
    var arr = $("#" + id).serializeArray();
    var jsonStr = "";
    jsonStr += '{';
    for (var i = 0; i < arr.length; i++) {
        jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
    }
    jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
    jsonStr += '}';
    var json = JSON.parse(jsonStr);
    return json;
}

//将表单数据转为json格式的字符串，当然也可以JSON.stringify(data)
function form2JsonStr(id) {
    var arr = $("#" + id).serializeArray();
    var jsonStr = "";
    jsonStr += '{';
    for (var i = 0; i < arr.length; i++) {
        jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'
    }
    jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
    jsonStr += '}';
    return jsonStr;
}